import * as THREE from 'three';
const model = new THREE.Group();
// 已知条件
// 一条线段两点坐标A、B
const A = new THREE.Vector3(0, 0, 10);
const B = new THREE.Vector3(100, 0, 10);
const material1 = new THREE.LineBasicMaterial({
	color: 0x0000ff
});
const geometry1 = new THREE.BufferGeometry().setFromPoints( [A,B] );
const line = new THREE.Line( geometry1, material1 );

// 判断p1、p2两点位于线段AB同一侧，还是异侧
const p1 = new THREE.Vector3(20, 0, 40);
const p2 = new THREE.Vector3(80, 0, -40);//与p1同侧
const geometry2 = new THREE.BufferGeometry();
geometry2.setFromPoints([p1,p2])
const material2 = new THREE.PointsMaterial({
    color : 0xff0000,
    size:10
})
const points = new THREE.Points(geometry2, material2);
const a1 = A.clone().sub(p1)//向量Ap1
const arrowA1 = new THREE.ArrowHelper(a1,p1,a1.length(),0x00ff00);
const b1 = B.clone().sub(p1)//向量Bp1
const arrowB1 = new THREE.ArrowHelper(b1,p1,b1.length(),0x0000ff);
const a2 = A.clone().sub(p2)//向量Ap2
const arrowA2 = new THREE.ArrowHelper(a2,p2,a2.length(),0xff00ff);
const b2 = B.clone().sub(p2)//向量Bp2
const arrowB2 = new THREE.ArrowHelper(b2,p2,b2.length(),0x00ffff);


const c1 = a1.clone().cross(b1)
const arrowC1 = new THREE.ArrowHelper(c1,p1,c1.length()/30,0x00ffff);
const c2 = a2.clone().cross(b2)
const arrowC2 = new THREE.ArrowHelper(c2,p2,c2.length()/30,0x00ffff);
// 计算c1 和c2的点乘
const cos = c1.clone().normalize().dot(c2.clone().normalize());
// 如果cos的值等于1，角度为0，在同一方向
if(cos>0){
    console.log('在同一方向，因为叉乘方向相同',cos);
}else{
    console.log('不在同一方向，因为叉乘方向相反',cos);
}
model.add(line,points,arrowA1,arrowB1,arrowA2,arrowB2,arrowC1,arrowC2)


export default {model};